var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    issign: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      tel: wx.getStorageSync('tel')
    })
    this.checkIn()
  },
  checkIn () {
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: 'https://miniapp.odeman.com/summercamp/sign.php', 
      data: {
        userid: wx.getStorageSync('userid')
      },
      method:'post',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success(res) {
        wx.hideLoading()
        console.log(res.data)
        var data = res.data
        if (data.status == "success") {
          that.setData({
            date: data.list.week,
            tag: data.list.tag,
            issign: data.list.issign,
            img:data.list.img
          })
        }
      }
    })
  },
  toCheckIn: function() {
    var _this = this
    if (this.data.issign) {
      wx.showToast({
        title: '主人，您签过啦',
        icon: 'none',
        duration: 4000
      })
    } else {
      wx.request({
        url: 'https://miniapp.odeman.com/summercamp/sign_ajax.php',
        data: {
          userid: wx.getStorageSync('userid')
        },
        method:'post',
        header: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        success(res) {
          console.log(res.data)
          var data = res.data
          if (data.code == 1) {
            wx.showToast({
              title: '主人，签到成功了哟',
              icon: 'none',
              duration: 4000
            })
          }
          _this.checkIn()
        }
      })
    }
  }
})